<!--
  - Copyright (c) 2018.
  - 北京九思金信科技有限公司对该文件内容保留所有权利。
  - 未经许可，不得私自拷贝、传播、发布、引用该文件内容，违者将被追究法律责任。
  -->

<template>
  <div class="customerManagement_box">
    <div class="customerManagement_title">
      <div class="customerManagement_title_return" @click="returnHistiy">
        <img src="@/pages/mobile/assets/img/Back@3x.png" alt />
        <span>任务中心</span>
      </div>
      <p>客户信息维护</p>
      <div class="customerManagement_title_img">
        <img src="@/pages/mobile/assets/img/Search@3x.png" @click="searchInfo" alt />
      </div>
    </div>
    <div class="scroll" ref="scroll">
      <scroll
        :loadDatas="customerManagementData"
        :pullUpLoad="pullUpLoad"
        :pulldown="pulldown"
        @pullingDown="loadDownData"
        @pullingUp="loadUpData"
        class="customerManagement_content"
      >
        <div
          class="customerManagement_content_item"
          v-for="item in customerManagementData"
          :key="item.id"
          @click="itemClick(item)"
          :class="
            item.customerType.label == '个人'
              ? 'customerManagement_content_item_gr'
              : 'customerManagement_content_item_qy'
          "
        >
          <div class="header_item_img">
            <i v-if="item.customerType.label == '企业'">个人</i>
            <i v-else>企业</i>
          </div>
          <h3>{{ item.customerName }}</h3>
          <p class="qy_title">社会统一信用码：</p>
          <p class="gr_title">身份证：</p>
          <em>{{ item.identityNo }}</em>
          <span>有限责任公司</span>
          <div class="footer__item_img"></div>
        </div>
        <i class="font_box"></i>
      </scroll>
    </div>
    <div class="customerManagement_fonter" @click="cameraInfo">
      <!-- <x-icon type="ios-plus" size="30"></x-icon> -->
      <x-icon type="ios-plus-empty" size="56"></x-icon>
      <!-- <button @click="cmaddindex">＋ 新建客户</button> -->
    </div>

    <transition name="cmdetailbox">
      <cm-detail
        ref="edit"
        class="cmdetail_b"
        :childDataType="itemDataType"
        @childReturnHistiy="shutItemDataInfo"
        v-if="CmDetail"
      ></cm-detail>
    </transition>
    <!-- 新建类型弹框 -->

    <!-- 相机弹框 -->
    <div
      class="CmIndex_alert"
      @click.stop="cameraInfoNo"
      :class="{ CmIndex_alert_active: camera }"
    >
      <div class="CmIndex_alert_box">
        <span class="CmIndex_alert_box_title">
          新建客户
        </span>
        <div class="CmIndex_alert_box_menu" @click.stop>
          <div class="CmIndex_alert_box_menu_item" @click="openCmAddIndex(3)">
            <img
              src="../../../../assets/appimg/customerManagement/cmAdd_gr_img.png"
              alt=""
            />
            <p>新增个人客户</p>
          </div>
          <div class="CmIndex_alert_box_menu_item" @click="openCmAddIndex(2)">
            <img
              src="../../../../assets/appimg/customerManagement/cmAdd_qy_img.png"
              alt=""
            />
            <p>新增企业客户</p>
          </div>
        </div>
        <div class="CmIndex_alert_box_action_box">
          <div class="CmIndex_alert_box_action">
            <x-icon
              type="ios-close-empty"
              size="56"
              style="color:#fff"
            ></x-icon>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import CmDetail from "./CmDetail.vue";
import Scroll from "@/pages/mobile/components/JoysScroll/JoysScroll";
import JoysLoading from "@/pages/mobile/components/JoysLoading/JoysLoading";
export default {
  name: "CustomerManagement",
  data () {
    return {
      camera: false, // 新建选择弹框
      CmDetail: false, //详情组件
      pulldown: true,
      pullUpLoad: true,
      customerManagementData: [],
      pageNum: 1,
      pageSizeNumber: 1,
      itemDataType: "" //信息类型
    };
  },
  components: {
    Scroll,
    CmDetail
  },
  methods: {
    openCmAddIndex (val) {
      this.$router.push({
        path: "/customerManagement/cmAddIndex",
        query:{
          val:val
        }
      });
    },
    // 点击调用选择弹框
    cameraInfo () {
      this.camera = true;
    },
    // 关闭选择弹框
    cameraInfoNo () {
      this.camera = false;
    },
    itemClick (val) {
      console.log(val, '试试')
      this.itemDataType = val.customerType.label;
      this.CmDetail = true;
      setTimeout(() => {
        this.$refs.edit.itemQueryData(val.customerType.label, val.customerId);
      }, 10);
    },
    shutItemDataInfo () {
      console.log("tag", "");
      this.CmDetail = false;
    },
    loadDownData () {
      setTimeout(() => {
        this.loadData(1);
        this.customerManagementData = [];
      }, 1000);
    },
    loadUpData () {
      setTimeout(() => {
        this.pageNum++;
        this.loadData(this.pageNum);
      }, 1000);
    },

    loadData (pageNum) {
      this.$axios({
        method: "post",
        url: "/joys-rest/lss-customer/custInfo/list",
        headers: {
          "AUTH-TOKEN": localStorage.getItem("AUTH-TOKEN"),
          "Content-Type": "application/json;charset=UTF-8"
        },
        params: {
          pageIndex: pageNum,
          pageSize: 10
          // filter: ""
        },
        data: {}
      })
        .then(res => {
          console.log(res, "hhhhhhhhhhhhhhhhhhhhhhhhh");
          this.customerManagementData = this.customerManagementData.concat(
            res.data.rows
          );
        })
        .catch(error => {
          console.log(error, "上传失败");
        });
    },
    searchInfo () { },
    returnHistiy () {
      this.$router.goBack();
    },
  },
  mounted () {
    this.loadData(1);
  }
};
</script>

<style scoped lang="less">
.customerManagement_box {
  position: fixed;
  z-index: 1000;
  width: 100%;
  height: 100%;
  background: #fbf9fe;
  overflow: hidden;
  .customerManagement_title {
    width: 100%;
    height: 0.44rem;
    text-align: center;
    line-height: 0.44rem;
    background: #ffffff;
    position: fixed;
    z-index: 201;
    box-shadow: inset 0 -1px 0 0 rgba(207, 207, 207, 0.2);
    .customerManagement_title_return {
      margin-top: -0.04rem;
      float: left;
      img {
        // width: 0.15rem;
        height: 0.205rem;
        padding-left: 0.085rem;
        padding-top: 0.02rem;
      }
      span {
        font-family: Regular;
        font-size: 0.17rem;
        color: #3e3e3e;
        letter-spacing: -0.41px;
        line-height: 0.22rem;
      }
    }
    p {
      font-family: PingFangSC-Semibold;
      font-size: 0.17rem;
      color: #3e3e3e;
      letter-spacing: -0.41px;
      text-align: center;
      height: 0.44rem;
      font-weight: 700;

      line-height: 0.44rem;
      margin-left: 0.7rem;
      margin-right: 0.7rem;
    }
    .customerManagement_title_img {
      margin-top: -0.46rem;
      float: right;
      margin-right: 0.2rem;
      img {
        margin-left: -0.05rem;
        height: 0.22rem;
      }
    }
  }
  .customerManagement_content {
    margin-top: 0.5rem;
    .customerManagement_content_item {
      margin: 0.1rem 0.16rem 0rem 0.16rem;
      background: #ffffff;
      box-shadow: 0 2px 0.07rem 0 rgba(0, 0, 0, 0.06);
      border-radius: 0.05rem;
      padding-left: 0.12rem;
      overflow: hidden;
      padding-top: 0.24rem;
      position: relative;
      height: 1.1rem;
      h3 {
        margin-top: 0.08rem;
        font-family: PingFangSC-Medium;
        font-size: 0.16rem;
        color: #3e3e3e;
        letter-spacing: 0;
        font-weight: 700;
        margin-bottom: 0.04rem;
        height: 0.21rem;
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        width: 70%;
      }
      p {
        font-family: PingFangSC-Regular;
        font-size: 0.12rem;
        color: #706967;
        letter-spacing: 0;
        margin-bottom: 0.04rem;
        opacity: 0.65;
        height: 0.17rem;
      }
      em {
        display: block;
        font-family: PingFangSC-Regular;
        font-size: 0.14rem;
        color: #706967;
        letter-spacing: 0;
        height: 0.2rem;
        line-height: 0.2rem;
        opacity: 0.65;
        height: 0.2rem;
      }
      span {
        font-family: PingFangSC-Regular;
        font-size: 0.12rem;
        color: #9c9795;
        letter-spacing: 0;
        display: block;
        position: absolute;
        bottom: 0.12rem;
        opacity: 0.65;
        left: 0.05rem;
        // transform: scale(0.84);
        display: none;
      }
      .footer__item_img {
        background-size: 100% 100%;
        position: absolute;
        bottom: 0px;
        right: 0px;
        width: 0.78rem;
        height: 0.9rem;
      }
      .header_item_img {
        margin-top: -0.24rem;
        margin-left: -0.12rem;
        width: 0.4rem;
        height: 0.18rem;
        overflow: hidden;
        border-bottom-right-radius: 5px;
        i {
          display: block;
          font-family: PingFangSC-Regular;
          font-size: 0.12rem;
          color: #ffffff;
          letter-spacing: 0;
          line-height: 0.18rem;
          box-sizing: border-box;
          // transform: scale(0.84);
          text-align: center;
        }
      }
      .qy_title {
        display: none;
      }
      .gr_title {
        display: none;
      }
    }
    .font_box {
      height: 0.9rem;
      display: block;
    }
    .customerManagement_content_item_qy {
      background-size: 50%;
      .header_item_img {
        background: #4555a0;
      }
      span {
        display: block;
      }
      .qy_title {
        display: block;
      }
      .footer__item_img {
        background: #ffffff
          url("../../../../assets/appimg/customerManagement/KX_enterprise_qy.png")
          no-repeat center center;
        background-size: 100% 100%;
      }
    }
    .customerManagement_content_item_gr {
      background-size: 50%;
      .header_item_img {
        background: #e5a83f;
      }
      .gr_title {
        display: block;
      }
      .footer__item_img {
        background: #ffffff
          url("../../../../assets/appimg/customerManagement/KX_enterprise_gr.png")
          no-repeat center center;
        background-size: 100% 100%;
      }
    }
  }
  .customerManagement_fonter {
    position: absolute;
    width: 0.56rem;
    bottom: 14px;
    right: 24px;
    height: 0.56rem;
    overflow: hidden;
    border-radius: 50%;
    background: #be9457;
    display: flex;
    justify-content: center;
    align-items: center;
    .vux-x-icon {
      fill: #fff;
    }
  }
  .cmdetail_b {
    position: absolute;
    width: 100%;
    height: 100%;
    transition: all 0.377s ease;
    box-sizing: border-box;
    overflow: auto;
    z-index: 600;
  }
  // 新建选择弹框

  .CmIndex_alert {
    .CmIndex_alert_box {
      position: fixed;
      left: 0;
      bottom: 0;
      height: 3.34rem;
      -webkit-transform: translate(0, 100%);
      -webkit-backface-visibility: hidden;
      backface-visibility: hidden;
      z-index: 5000;
      width: 100%;
      background-color: #fff;
      transition: -webkit-transform 0.3s;
      transition: transform 0.3s;
      transition: transform 0.3s, -webkit-transform 0.3s;
      text-align: center;
      .CmIndex_alert_box_title {
        font-family: PingFangSC-Regular;
        font-size: 16px;
        color: #443a38;
        letter-spacing: 0;
        margin: 0.2rem 0;
        display: block;
      }
      .CmIndex_alert_box_menu {
        // margin-top: 0.24rem;
        display: flex;
        justify-content: center;
        .CmIndex_alert_box_menu_item {
          // float: left;
          width: 1.44rem;
          height: 1.24rem;
          background: #f9f9f9;
          border-radius: 16px;
          // display: flex;
          // // align-items: center;
          // justify-content: center;
          img {
            height: 0.72rem;
            width: 0.72rem;
            display: block;
            margin: 0 auto;
            margin-top: 0.12rem;
          }
          p {
            height: 0.4rem;
            line-height: 0.4rem;
            font-family: PingFangSC-Regular;
            font-size: 14px;
            color: #443a38;
            letter-spacing: 0;
          }
        }
        .CmIndex_alert_box_menu_item:first-child {
          margin-right: 0.15rem;
        }
        .CmIndex_alert_box_menu_item:active {
          background: #f4f4f4;
        }
      }
      .CmIndex_alert_box_action_box {
        // background: #f9fafb;
        margin-top: 0.3rem;
        width: 100%;
        height: 0.56rem;
        overflow: hidden;
        padding-top: 0.08rem;
        display: flex;
        align-items: center;
        justify-content: center;
        .CmIndex_alert_box_action {
          width: 0.56rem;
          height: 0.56rem;
          border-radius: 50%;
          background: #be9457;
          display: flex;
          justify-content: center;
          align-items: center;
          .vux-x-icon {
            fill: #fff;
          }
        }
        .CmIndex_alert_box_action_cell:active {
          background: #f4f4f4;
        }
      }
    }
  }
  .CmIndex_alert_active {
    position: fixed;
    z-index: 1000;
    top: 0;
    right: 0;
    left: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.6);
    .CmIndex_alert_box {
      transform: translate(0, 4%);
    }
  }
  .cmdetailbox-enter,
  .cmdetailbox-leave-active {
    opacity: 0;
    -webkit-transform: translate(-50px, 0);
    transform: translate(-50px, 0);
  }

  .cmdetailbox-leave-active,
  .cmdetailbox-enter {
    opacity: 0;
    -webkit-transform: translate(50px, 0);
    transform: translate(50px, 0);
  }
}
</style>
